<?php
//$this->Html->scriptBlock($scriptWindowMsg, array('inline' => false));
$this->Html->scriptBlock($auto_complete, array('inline' => false));
$this->Html->script(array('aihcontacts'), false);
?>
<div class="title-body-content"><?php echo $title_for_layout; ?></div>
<div class="wrapper-form clearfix">
    <?php
    if($rel == 'browse') {
        $formUrl = array('controller' => 'aihcontacts', 'action' => 'add', 'rel' => 'browse', 'contacttype' => $contacttype);
    } else {
        $formUrl = array('controller' => 'aihcontacts', 'action' => 'add');
    }
    echo $this->Form->create('Aihcontact', array('url' => $formUrl, 'type' => 'text'));
    ?>
    <table class="tbl-contact1" cellpadding="0" cellspacing="0" border="0" style="width: 90%">
        <tr>
            <td class="td-sp-contact"><?php echo __('Contact Name'); ?> (*):</td>
            <td class="td-inp-contact" style="width: 70%">
                <?php
                echo $this->Form->input('name', array(
                    'class' => 'inp-contact-name',
                    'label' => false,
                    'div' => false,)
                );
                ?>
            </td>
        </tr>
        <tr>
            <td class="td-sp-contact"><?php echo __('Country Name'); ?> (*):</td>
            <td class="td-inp-contact" style="width: 70%">
                <?php
                echo $this->Form->input('country', array(
                    'class' => 'inp-contact-name',
                    'label' => false,
                    'div' => false,)
                );
                ?>
            </td>
        </tr>
        <tr class="tbl-contact-content">
            <td class="td-sp-contact"><?php echo __('Contact Type'); ?> :</td>
            <td class="td-inp-contact">
                <?php
                echo $this->Form->input('Contacttype.Contacttype', array(
                    'multiple' => false,
                    'empty' => false,
                    'class' => 'sel-contact-type',
                    'label' => false,
                    'div' => false,)
                );
                ?>
            </td>
        </tr>
        <tr class="tbl-contact-content">
            <td class="td-sp-contact"><?php echo __('Contact Address'); ?> (*):</td>
            <td class="td-inp-contact">
                <?php
                echo $this->Form->textarea('address', array(
                    'class' => 'inp-contact-address',
                    'label' => false,
                    'div' => false,)
                );
                ?>
            </td>
        </tr>
    </table>
    <div class="wrapper-bank-detail clearfix">
        <span class="title-payment-schedule"><?php echo __('BANK DETAIL'); ?></span>
        <?php
        echo $this->Form->input('Bank1.Bank1', array(
            'multiple' => false,
            'empty' => false,
            'class' => 'sel-contact-type',
            'label' => false,
            'div' => false,)
        );
        ?>
        <div class="wrapper-button-bank-detail">
            <div class="button-aihre button-blue">
                <a href="JavaScript:void(0);" class="addBankField" rel="1"><?php echo __('ADD'); ?></a>
            </div>
        </div>
        <?php //echo $this->Layout->bankField(); ?>
        <span id="bankField1"></span>
        <div class="wrapper-bank-detail clearfix">
            <span class="title-payment-schedule"><?php echo __('CORRESPONDENT BANK'); ?></span>
            <?php
            echo $this->Form->input('Bank2.Bank2', array(
                'multiple' => false,
                'empty' => false,
                'class' => 'sel-contact-type',
                'label' => false,
                'div' => false,)
            );
            ?>
            <div class="wrapper-button-bank-detail">
                <div class="button-aihre button-blue">
                    <a href="JavaScript:void(0);" class="addBankField" rel="2"><?php echo __('ADD'); ?></a>
                </div>
            </div>
            <?php //echo $this->Layout->bankField(null, 2); ?>
            <span id="bankField2"></span>
        </div>
    </div>
    <div class="wrapper-button-form">
        <div class="button-form">
            <div class="button-aihre button-blue"><a href="#" class="save" >SAVE</a></div>
            <div class="button-aihre button-blue">
                <?php
                if ($rel == 'browse') {
                    echo $this->Html->link(__('CANCEL'), array('plugin' => null, 'controller' => 'aihcontacts', 'action' => 'browse', 'contacttype' => $contacttype));
                } else {
                    echo $this->Html->link(__('CANCEL'), array('plugin' => null, 'controller' => 'aihcontacts', 'action' => 'index'));
                }
                ?>
            </div>
        </div>
    </div>
    <?php
    echo $this->Form->end();
    ?>
</div>
<?php
$validForm = "
    $(function(){
        $('a.save').click(function(){
            var error = true;
            if($('#AihcontactName').val()==''){
                $('#AihcontactName').parent().children('label.error-message').remove();
                $('#AihcontactName').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AihcontactName').parent().children('label.error-message').remove();
            }
            if($('#AihcontactCountry').val()==''){
                $('#AihcontactCountry').parent().children('label.error-message').remove();
                $('#AihcontactCountry').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AihcontactCountry').parent().children('label.error-message').remove();
            }
            if($('#AihcontactAddress').val()==''){
                $('#AihcontactAddress').parent().children('label.error-message').remove();
                $('#AihcontactAddress').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AihcontactAddress').parent().children('label.error-message').remove();
            }
            if (error) {
                $('#AihcontactAdminAddForm').submit();
            }
        });
    });";
$this->Html->scriptBlock($validForm, array('inline' => false));
?>